package com.blb.thread;

/**
 * 守护线程
 */
public class DaemonDemo {

    public static void main(String[] args) {
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                for (int j = 0;j < 10;j++){
                    System.out.println(Thread.currentThread().getName() +"-->" +j);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();
        }
        //守护线程
        Thread thread = new Thread(() -> {
            while (true){
                System.out.println("我守护你们");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.setDaemon(true);
        thread.start();
    }
}
